package com.tshopping.dao;

import com.tshopping.bean.Cart;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;

@Repository
public interface CartDao {

    @Insert("insert into cart(user,goods,parameter,number,time) values(#{user},#{goods},#{parameter},#{number},#{time})")
    boolean insertCart(@Param("user") int user,@Param("goods") int goods,@Param("parameter") int parameter,@Param("number") int number, @Param("time") String time);

    @Select("select * from cart where user=#{user} limit #{start},#{size}")
    ArrayList<Cart> selectCartByUserID(@Param("user") int user,@Param("start") int start,@Param("size") int size);

    @Select("select count(*) from cart where user=#{user}")
    int  selectCartCountByUser(@Param("user") int user);

    @Delete("delete from cart where id=#{id}")
    boolean deleteCartById(@Param("id") int id);

    @Update("update cart set number=#{number} where id=#{id}")
    boolean updateCartById(@Param("number") int number,@Param("id") int id);

    @Select("select * from cart where goods=#{goods} and parameter=#{parameter} and user=#{user}")
    Cart selectCartByGoodsIdAndParameter(@Param("goods") int goods,@Param("parameter") int parameter,@Param("user") int user);
}
